﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="chRoom.aspx.cs" Inherits="chatblog.usercate.chRoom"  Title ="好友聊天"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>好友聊天</title>
    <link href="css/chatall.css" rel="stylesheet" type="text/css" />
    <link href="css/chRoom.css" rel="stylesheet" type="text/css" />
    <script src="js/chatall.js" type="text/javascript"></script> 
    <script src="../js/jquery-1.3.2.min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="maskDiv" style =" position :absolute ;top:0px; left :0px;   visibility :hidden ; background-color :#666;  z-index :1;"></div>
    <div>
          <div style =" width :100%; height :500px;  ">
            <div id="UserCate" class="UserCate" style="width:97%; height :400px;  ">
                <div id="DoorP" runat="server" >
                    <h2  class="h2style" id="702743">默认分组</h2>
                    <div class="content"  style=" background-color :#ECECEC ;  overflow :auto " >
                        <br /><br /><br /><br/><br/> <br /><br /><br /><br/><br/><br /><br /><br /><br/><br/> 
                    </div>
                </div>
                <div id="CateTool"  style =" display :none; text-align :left ; height:30px; background:url('img/tagleft0.gif') no-repeat ">
                </div>                
            </div>
                
                     
                <%--组内用户 右键菜单--%>
                <div id="bmenu" style="position: absolute; display: none; top: 0px; left: 0px; width: 130px;
                    margin: 0px; padding: 2px; border: 1px solid #cccccc; background-color: #CEE2FF;">
                    <ul>
                        <li id="rename">修改昵称</li>
                        <li id="del">删除</li>
                        <li id="edit" >更改分组
                        </li>
                        <li class="separator" style="height: 1px; vertical-align: middle;" id="separator">
                        </li>
                        <li id="add">添加好友</li>
                        <li id="prop">查看详情</li>
                    </ul>
                </div>
                <div id="GroupMenu" style="position: absolute; display: none; top: 0px; left: 0px;
                    width: 130px; margin: 0px; padding: 2px; border: 1px solid #cccccc; background-color: #CEE2FF;">
                    <ul>
                        <li id="addGroup">添加组</li>
                        <li id="addUser">添加好友</li>
                        <li class="separator" style="height: 1px; vertical-align: middle;" id="Li3"></li>
                        <li id="deleteGroup">删除组</li>
                        <li id="renameGroup">重命名该组</li>
                    </ul>
                </div>
         </div>
    </div>
    </form>
    <script type="text/javascript">
            //浏览器类型
            var Sys = {};
            var ua = navigator.userAgent.toLowerCase();
            if (window.ActiveXObject)
                Sys.ie = ua.match(/msie ([\d.]+)/)[1]
            else if (document.getBoxObjectFor)
                Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1]
            else if (window.MessageEvent && !document.getBoxObjectFor)
                Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1]
            else if (window.opera)
                Sys.opera = ua.match(/opera\/([\d.]+)/)[1]
            else if (window.openDatabase)
                Sys.safari = ua.match(/version\/([\d.]+)/)[1];

            // 验证是否为邮箱地址
            function verifyAddress(email) {
                var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
                flag = pattern.test(email);
                if (flag) {
                    return true;
                }
                else {
                    return false;
                }
            }
            var maskDivId = "maskDiv";
            var doorPId = "DoorP"; //"DoorP"; 
            var currentRenameGroup = null;
            var currentAddGroup = null;
            var newGroupid = "add";
            var onum = 0;
            var closeState = new Array();
            var totalH = 495;
            var ch = 495;
            var contenh = 27;
            var userIdSpanListManage = new Array();
            var userIdTimeListManage = new Array();
            var groupIdTimeListManage = new Array();

            function showMe(Cid, Oid) {
                var h = parseInt(Ds[Cid].style.height);
                var h2 = parseInt(Ds[Oid].style.height);
                var dH = ch;
                if (h > 0) {
                    h = h - Math.ceil(h / 3);
                    Ds[Cid].style.height = h + "px";
                };
                if (h2 < dH) {
                    h2 = h2 + Math.ceil((dH - h2) / 3);
                    Ds[Oid].style.height = h2 + "px";
                };

                if (h <= 0 && h2 >= dH) {
                    clearTimeout(closeState[Cid]);
                    return false;
                };
                closeState[Cid] = setTimeout("showMe(" + Cid + "," + Oid + ")");
            }

            var Ds = $("#" + doorPId + " > div"); //ctl00_ctl00_ContentPlaceHolder1_BodyContentPlaceHolder_DoorP
            var Ts = $("#" + doorPId + " > h2");
            //        if(Ds.length != Ts.length){alert("初始化失败!");}
            for (var i = 0; i < Ds.length; i++) {
                userIdSpanListManage.push(Ds.innerText);
                //userIdTimeListManage.push("");
                ch = (totalH - (Ds.length) * contenh);
                if (i == onum) {
                    Ds[i].style.height = ch + "px";
                    Ts[i].className = "title02";
                }
                else {
                    Ds[i].style.height = "0px";
                    Ts[i].className = "title02";
                }

                Ts[i].value = i;
                Ts[i].onclick = function() {
                    if (onum == this.value) { return false; };
                    Ts[onum].className = "title02";
                    Ts[this.value].className = "title02";
                    for (var i = 0; i < closeState.length; i++) { clearTimeout(closeState[i]); }
                    showMe(onum, this.value);
                    onum = this.value;
                }
            }

            function InitAgain() {
                Ds = $("#" + doorPId + " > div");
                Ts = $("#" + doorPId + " > h2");
                if (onum >= Ts.length)
                    onum = 0;

                userIdSpanListManage = new Array();
                for (var i = 0; i < Ds.length; i++) {
                    userIdSpanListManage.push(Ds.innerText);
                    if (currentAddGroup != null)
                        ch = (totalH - (Ds.length + 1) * contenh);
                    else
                        ch = (totalH - (Ds.length) * contenh);
                    if (i == onum) { Ds[i].style.height = ch + "px"; Ts[i].className = "title02"; } else { Ds[i].style.height = "0px"; Ts[i].className = "title02"; }
                    Ts[i].value = i;
                    Ts[i].onclick = function() {
                        if (onum == this.value) { return false; };
                        Ts[onum].className = "title02";
                        Ts[this.value].className = "title02";
                        for (var i = 0; i < closeState.length; i++) { clearTimeout(closeState[i]); }
                        showMe(onum, this.value);
                        onum = this.value;
                    }
                }
            }
            function RefreshGroupDiv() {
                var doorPDiv = document.getElementById(doorPId);
                doorPDiv.innerHTML = chatblog.usercate.chRoom.GetDoorPInnerHtml().value;
                currentAddGroup = null;
                currentRenameGroup = null;
                InitAgain();
                userIdTimeListManage = new Array();
            }


            function saveH2(h2Titleid, titleInputid) {
                var titleInput = document.getElementById(titleInputid);
                var result = chatblog.usercate.chRoom.AddGroup(titleInput.value);
                if (result.value != null && result.value == "") {
                    RefreshGroupDiv();
                }
                else {
                    alert("操作失败:" + result.value);
                }
            }
            function renameH2(groupid, oldName, newNameTextBox) {
                if (newNameTextBox.value.replace(/\s/g, "") == "") {
                    alert('重命名不能为空或空格！')
                    return;
                }
                var result = chatblog.usercate.chRoom.UpdateGroup(groupid, oldName, newNameTextBox.value);
                if (result.value != null && result.value == "") {
                    RefreshGroupDiv();
                }
                else {
                    alert("操作失败:"+result.value);
                }
            }

            //添加好友组
            function addGroupOperate() {
                if (currentAddGroup != null) {
                    alert("已经打开一个新建的组，请继续编辑！");
                    return;
                }

                newGroupid += "1";
                var doorPDiv = document.getElementById(doorPId);
                var h2Ele = document.createElement("H2");

                h2Ele.id = newGroupid;
                h2Ele.innerHTML = "&nbsp;<input  id=\"titleInput\" type =\"text\" value=\"\" style =\" width :40%\"/><input id=\"Button2\" type=\"button\" value=\"添加\"  onclick =\"saveH2('" + newGroupid + "','titleInput');\"/><input id=\"Button3\" type=\"button\" value=\"取消\" onclick=\"RefreshGroupDiv();\"/>";
                doorPDiv.appendChild(h2Ele);
                h2Ele.className = "editGroup";
                currentAddGroup = h2Ele;
                InitAgain();
            }
            //重命名好友组
            function renameGroupOperate(cobj) {
                if (currentRenameGroup != null) {
                    alert("已经存在正在重命名的组，请结束上一操作后再新的重命名！");
                    return;
                }
                if (cobj.childNodes[0].nodeName != "#text") {
                    alert("对不起，您有新消息，请处理完消息后再重命名！");
                    return;
                }
                var oldName = cobj.childNodes[0].nodeValue;
                cobj.innerHTML = "<input  id=\"titleInput\" type =\"text\" value=\"" + oldName + "\" style =\" width :40%\"/><input id=\"Button2\" type=\"button\" value=\"修改\"  onclick =\"renameH2('" + cobj.id + "','" + oldName + "',titleInput)\"/><input id=\"Button3\" type=\"button\" value=\"取消\" onclick=\"RefreshGroupDiv();\"/>";
                cobj.className = "editGroup";
                currentRenameGroup = cobj;
            }


            window.onload = function() {
                var currentuseridReslut = chatblog.usercate.chRoom.GetCurrentUserID();
                if (currentuseridReslut.value == null || (currentuseridReslut.value != null && currentuseridReslut.value == "")) {
                    alert("对不起，您还未登录，请先登录!");
                    if (window.opener != null) {
                        window.opener.location.href = "../member/login.aspx";
                    }
                    window.opener = null;
                    window.close();
                }
            }
    </script>
    <script src="js/chRoom.js" type="text/javascript"></script>
</body>
</html>
